﻿@{
    Layout = null;
    var documentinfo = (ArticleContent)ViewBag.DocumentInfo;
}

@if (ViewBag.DocumentInfo == null)
{
    <span>文章不存在，请选择其它文章查看！</span>
}
else
{
    { documentinfo.DocContent = "\n" + documentinfo.DocContent; }
    <h1 class="site-h1">@documentinfo.Title</h1>
    <div id="details_content" class="md_css" style="display:none;">
        @documentinfo.DocContent
    </div>
    <script>
        if ('@documentinfo.OriginType' == '1') {
            @*var options = {
                elm: "details_content", url: "@documentinfo.OriginUrl", paramters: "", loadIndex: 1,
                successCallBack: function () {
                    debugger
                    document.getElementById('details_content').innerHTML =
                        marked($("#details_content").html());
                }
            };*@

            var xhr = new XMLHttpRequest();
            xhr.timeout = 3000;
            xhr.ontimeout = function (event) {
                alert("请求超时！");
            }
            var formData = new FormData();
            xhr.open('GET', '@documentinfo.OriginUrl');
            xhr.send(formData);
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    document.getElementById('details_content').innerHTML =
                        xhr.responseText;
                }
            }

            @*var url = "@documentinfo.OriginUrl";             //获取目标地址信息
            if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();                  //FireFox、Opera等浏览器支持的创建方式
            } else {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式
            }
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    document.getElementById('details_content').innerHTML =
                        marked(xmlHttp.responseText);
                }
            }; 
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);*@


            @*$("#details_content").load("@documentinfo.OriginUrl");
            document.getElementById('details_content').innerHTML =
                marked($("#details_content").html());*@
            //freejs.loadHtml(options);
        }
        else {
            if ('@documentinfo.EditorMode' == '0') {
                marked.setOptions({
                    renderer: new marked.Renderer(),
                    gfm: true,
                    tables: true,
                    breaks: true,
                    pedantic: false,
                    sanitize: false,
                    smartLists: true,
                    smartypants: false,
                });
                marked.setOptions({
                    highlight: function (code) {
                        return hljs.highlightAuto(code).value;
                    }
                });
                document.getElementById('details_content').innerHTML =
                    marked($("#details_content").html());
            }
            else {
                //直接里面的内容就是HTML
            }
        }
        $("#details_content").show();
    </script>
}